package org.jin.jinaicode.service;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import jakarta.servlet.http.HttpServletRequest;
import org.jin.jinaicode.common.BaseResponse;
import org.jin.jinaicode.common.DeleteRequest;
import org.jin.jinaicode.model.dto.user.AppAddDTO;
import org.jin.jinaicode.model.dto.user.AppQueryDTO;
import org.jin.jinaicode.model.dto.user.AppUpdateDTO;
import org.jin.jinaicode.model.dto.admin.AppQueryAdminDTO;
import org.jin.jinaicode.model.dto.admin.AppUpdateAdminDTO;
import org.jin.jinaicode.model.dto.admin.AppFeatureDTO;
import org.jin.jinaicode.model.entity.App;
import org.jin.jinaicode.model.entity.User;
import org.jin.jinaicode.model.vo.AppVO;
import reactor.core.publisher.Flux;
import org.jin.jinaicode.model.dto.user.AppPublicDTO;

/**
 * 应用 服务层。
 *
 * @author 小堇
 */
public interface AppService extends IService<App> {

  /**
   * 创建应用
   */
  BaseResponse<Long> addApp(AppAddDTO appAddDTO, HttpServletRequest request);

  /**
   * 根据 id 修改自己的应用
   */
  BaseResponse<Boolean> updateApp(AppUpdateDTO appUpdateDTO, HttpServletRequest request);

  /**
   * 更新应用公开状态
   */
  BaseResponse<Boolean> updateAppPublicStatus(AppPublicDTO appPublicDTO, HttpServletRequest request);

  /**
   * 根据 id 删除自己的应用
   */
  BaseResponse<Boolean> deleteApp(DeleteRequest deleteRequest, HttpServletRequest request);

  /**
   * 根据 id 查看应用详情
   */
  BaseResponse<AppVO> getAppById(Long id, HttpServletRequest request);

  /**
   * 分页查询自己的应用列表
   */
  BaseResponse<Page<AppVO>> listMyAppByPage(AppQueryDTO appQueryDTO, HttpServletRequest request);

  /**
   * 分页查询精选的应用列表
   */
  BaseResponse<Page<AppVO>> listFeaturedAppByPage(AppQueryDTO appQueryDTO, HttpServletRequest request);

  /**
   * 分页查询所有精选应用列表（公开接口）
   */
  BaseResponse<Page<AppVO>> listAllFeaturedAppByPage(AppQueryDTO appQueryDTO);

  /**
   * 分页查询公开应用列表（公开接口）
   */
  BaseResponse<Page<AppVO>> listPublicAppByPage(AppQueryDTO appQueryDTO);

  /**
   * 管理员根据 id 删除任意应用
   */
  BaseResponse<Boolean> deleteAppByAdmin(DeleteRequest deleteRequest, HttpServletRequest request);

  /**
   * 管理员根据 id 更新任意应用
   */
  BaseResponse<Boolean> updateAppByAdmin(AppUpdateAdminDTO appUpdateAdminDTO, HttpServletRequest request);

  /**
   * 管理员分页查询应用列表
   */
  BaseResponse<Page<AppVO>> listAppByPageByAdmin(AppQueryAdminDTO appQueryAdminDTO, HttpServletRequest request);

  /**
   * 管理员根据 id 查看应用详情
   */
  BaseResponse<AppVO> getAppByIdByAdmin(Long id, HttpServletRequest request);

  /**
   * 管理员设置/取消精选应用
   */
  BaseResponse<Boolean> setAppFeature(AppFeatureDTO appFeatureDTO, HttpServletRequest request);

  /**
   * 生成应用代码
   */
  Flux<String> chatToGenCode(Long appId,String userMessage,  User loginUser);

  /**
   * 应用部署
   */
  String deployApp(Long appId,User loginUser);
}
